#  三种定义字符串的形式
#  '' ""  ''' '''
#  字符串拼接  "" + "" 拼接   * 多次重复
new = "1" + "t"
times = "l" * 3
print(new)
print(times)

#  转义字符 \ 和 r
str = r"world i'm"
print(str)

# 字符串包含
print("t" in "abdt")
print("t" not in "abdt")

#  字符串长度
print(len("kklkjhd"))

# 字符串切片 start:end:step
print("kl"[0])
print("kl3333"[-1])
print("kl3333"[1:3])
print("123456789"[1:7])
print("123456789"[1:7:2])
print("123456789"[::-1])

# 字符串遍历
s = "alsj"
for i in range(len(s)):
    print(f"{i} : {s[i]}")

for ele in s:
    print(ele)

#  字符串大小写
print("ni hao".capitalize())
print("ni hao".title())
print("ni hao".upper())
print("ni hao".lower())

# 字符串查找
print("ni hao".find("t"))
print("ni hao".index("h"))

# 字符串格式化 f
print("{}-{}".format(100,"pp"))


# 字符串去除空格
print(" ni hao ".strip())

# 字符串替换
print("hello".replace("hell", "world"))

# 字符串拆分与合并
print("ni hao".split())
print("ni hao".split("a"))
print(" ni hao ".join(["t","o"]))



# 字符串编码
print("ni hao 张三".encode("utf8"))
print("ni hao 张三".encode("gbk"))
print("ni hao 张三".encode("utf8").decode("utf8"))
